home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form custedit
- Caption = "Customer View/Edit"
- ClientHeight = 5130
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 7695
- Height = 5535
- Left = 1035
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- ScaleHeight = 5130
- ScaleWidth = 7695
- Top = 1140
- Width = 7815
- Begin CommandButton ButtonDone
- Caption = "E&xIt"
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 12
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 615
- Left = 6120
- TabIndex = 19
- Top = 4200
- Width = 975
- End
- Begin CommandButton ButtonDelete
- Caption = "&Delete"
- Height = 615
- Left = 4440
- TabIndex = 22
- Top = 4200
- Visible = 0 'False
- Width = 1095
- End
- Begin CommandButton ButtonCancel
- Caption = "&Cancel"
- Height = 615
- Left = 1920
- TabIndex = 21
- Top = 4200
- Visible = 0 'False
- Width = 1095
- End
- Begin CommandButton ButtonOK
- Caption = "&OK"
- Height = 615
- Left = 360
- TabIndex = 20
- Top = 4200
- Visible = 0 'False
- Width = 975
- End
- Begin CommandButton ButtonNew
- Caption = "&Add"
- Height = 495
- Left = 6120
- TabIndex = 18
- Top = 3240
- Width = 975
- End
- Begin TextBox Zip
- Height = 375
- Left = 2160
- TabIndex = 6
- Text = " "
- Top = 2880
- Width = 1335
- End
- Begin TextBox city
- Height = 375
- Left = 2160
- TabIndex = 5
- Text = " "
- Top = 2400
- Width = 3375
- End
- Begin CommandButton ButtonEdit
- Caption = "&Edit"
- Height = 495
- Left = 6120
- TabIndex = 17
- Top = 2280
- Width = 975
- End
- Begin TextBox address
- Height = 375
- Left = 2160
- TabIndex = 4
- Text = " "
- Top = 1920
- Width = 3375
- End
- Begin CommandButton ButtonLast
- Caption = "&Last"
- Height = 375
- Left = 6720
- TabIndex = 16
- Top = 1560
- Width = 735
- End
- Begin CommandButton ButtonFirst
- Caption = "&First"
- Height = 375
- Left = 5880
- TabIndex = 15
- Top = 1560
- Width = 735
- End
- Begin TextBox firstname
- Height = 375
- Left = 2160
- TabIndex = 3
- Text = " "
- Top = 1440
- Width = 2055
- End
- Begin CommandButton ButtonNext
- Caption = "&Next"
- Height = 375
- Left = 6720
- TabIndex = 14
- Top = 960
- Width = 735
- End
- Begin CommandButton ButtonPrior
- Caption = "&Prior"
- Height = 375
- Left = 5880
- TabIndex = 13
- Top = 960
- Width = 735
- End
- Begin TextBox lastname
- Height = 375
- Left = 2160
- TabIndex = 2
- Text = " "
- Top = 960
- Width = 2055
- End
- Begin TextBox custnumber
- Height = 375
- Left = 2160
- TabIndex = 1
- Text = " "
- Top = 480
- Width = 1215
- End
- Begin CommandButton ButtonFind
- Caption = "&Get"
- Height = 495
- Left = 6120
- TabIndex = 11
- Top = 240
- Width = 975
- End
- Begin Label total_spent
- BorderStyle = 1 'Fixed Single
- Caption = " "
- Height = 375
- Left = 4440
- TabIndex = 26
- Top = 3480
- Width = 1095
- End
- Begin Label Label8
- Caption = "YTD Spent:"
- Height = 255
- Left = 3120
- TabIndex = 25
- Top = 3480
- Width = 1095
- End
- Begin Label tapes_out
- BorderStyle = 1 'Fixed Single
- Caption = " "
- Height = 375
- Left = 2160
- TabIndex = 24
- Top = 3480
- Width = 855
- End
- Begin Label Label7
- Caption = "Tapes out:"
- Height = 255
- Left = 720
- TabIndex = 23
- Top = 3480
- Width = 1335
- End
- Begin Label Label6
- Caption = "Zip:"
- Height = 255
- Left = 720
- TabIndex = 10
- Top = 3000
- Width = 975
- End
- Begin Label Label5
- Caption = "City:"
- Height = 375
- Left = 720
- TabIndex = 9
- Top = 2520
- Width = 1215
- End
- Begin Label Label4
- Caption = "Address:"
- Height = 255
- Left = 720
- TabIndex = 8
- Top = 2040
- Width = 1215
- End
- Begin Label Label3
- Caption = "First name:"
- Height = 255
- Left = 720
- TabIndex = 7
- Top = 1560
- Width = 1335
- End
- Begin Label Label2
- Caption = "Last name:"
- Height = 255
- Left = 720
- TabIndex = 0
- Top = 1080
- Width = 1335
- End
- Begin Label Label1
- Caption = "Number:"
- Height = 375
- Left = 720
- TabIndex = 12
- Top = 600
- Width = 975
- End
- Dim iMode As Integer
- Dim blankcustrec As CUST
- Dim savecustrec As CUST
- Const EDIT_MODE = 0
- Const ADD_MODE = 1
- Const VIEW_MODE = 2
- Sub ButtonCancel_Click ()
- If iMode = ADD_MODE Then
- custrec = savecustrec
- rc = GetCustomerRec(DBKEYED)
- If rc Then
- rc = GetCustomerRec(DBFIRST)
- End If
- End If
- FieldsToForm
- SetEditMode VIEW_MODE
- End Sub
- Sub ButtonDelete_Click ()
- '
- ' check if user pressed OK or CANCEL
- '
- Msg$ = "OK to delete?"
- rc = MsgBox(Msg$, MB_OKCANCEL + MB_ICONQUESTION, "DELETE")
- If rc = IDCANCEL Then
- SetEditMode VIEW_MODE
- Exit Sub
- End If
- rc = DeleteCustomerRec()
- If rc Then
- MsgBox "Delete failed, code: " + Str$(rc)
- Beep
- End If
- rc = GetCustomerRec(DBNEXT)
- If rc Then
- rc = GetCustomerRec(DBLAST)
- End If
- FieldsToForm
- SetEditMode VIEW_MODE
- End Sub
- Sub ButtonDone_Click ()
- Unload custedit
- End Sub
- Sub ButtonEdit_Click ()
- screen.MousePointer = POINTER_HOURGLASS
- rc = GetCustomerRecForUpdate()
- If rc Then
- screen.MousePointer = POINTER_DEFAULT
- Exit Sub
- End If
- '
- ' Move the fields to the form again
- ' In a network environment, someone could have
- ' changed the record since last time is was shown
- '
- FieldsToForm
- SetEditMode EDIT_MODE
- screen.MousePointer = POINTER_DEFAULT
- End Sub
- Sub ButtonFind_Click ()
- FormToFields
- rc = GetCustomerRec(DBKEYED)
- If rc Then
- Exit Sub
- End If
- FieldsToForm
- End Sub
- Sub ButtonFirst_Click ()
- rc = GetCustomerRec(DBFIRST)
- If rc = DB_OK Then
- FieldsToForm
- End If
- End Sub
- Sub ButtonLast_Click ()
- rc = GetCustomerRec(DBLAST)
- If rc = DB_OK Then
- FieldsToForm
- End If
- End Sub
- Sub ButtonNew_Click ()
- Dim numvalue As Long
- SetEditMode ADD_MODE
- savecustrec = custrec
- rc = GetCustomerRec(DBLAST)
- If rc Then
- numvalue = 1
- Else
- numvalue = Val(custrec.custnumber)
- End If
- numvalue = numvalue + 1
- custrec = blankcustrec
- custrec.custnumber = LTrim$(Str$(numvalue))
- FieldsToForm
- End Sub
- Sub ButtonNext_Click ()
- rc = GetCustomerRec(DBNEXT)
- If rc = DB_OK Then
- FieldsToForm
- End If
- End Sub
- Sub ButtonOK_Click ()
- FormToFields
- If iMode = ADD_MODE Then
- rc = AddCustomerRec()
- End If
- If iMode = EDIT_MODE Then
- rc = UpdateCustomerRec()
- End If
- '
- ' Assume if one of these failed, a message was
- ' already displayed as part of the function.
- '
- ' What to do if the add or update failed?
- ' For now invoke the CANCEL routine as though
- ' the user clicked the cancel button.
- '
- If rc Then
- ButtonCancel_Click
- Exit Sub
- End If
- '
- ' Return to view mode
- '
- SetEditMode VIEW_MODE
- End Sub
- Sub ButtonPrior_Click ()
- rc = GetCustomerRec(DBPRIOR)
- If rc = DB_OK Then
- FieldsToForm
- End If
- End Sub
- Sub FieldsToForm ()
- custnumber.text = custrec.custnumber
- lastname.text = custrec.lastname
- firstname.text = custrec.firstname
- address.text = custrec.address
- city.text = custrec.city
- zip.text = custrec.zip
- tapes_out.caption = Str$(custrec.tapes_out)
- total_spent.caption = Str$(custrec.total_spent)
- End Sub
- Sub Form_Load ()
- screen.MousePointer = POINTER_HOURGLASS
- rc = GetCustomerRec(DBFIRST)
- If rc = DB_OK Then
- FieldsToForm
- End If
- SetEditMode VIEW_MODE
- screen.MousePointer = POINTER_DEFAULT
- End Sub
- Sub FormToFields ()
- custrec.custnumber = custnumber.text
- custrec.lastname = lastname.text
- custrec.firstname = firstname.text
- custrec.address = address.text
- custrec.city = city.text
- custrec.zip = zip.text
- End Sub
- Sub SetEditMode (ByVal mode%)
- If mode = EDIT_MODE Or mode = ADD_MODE Then
- ButtonFirst.visible = False
- ButtonNext.visible = False
- ButtonPrior.visible = False
- ButtonLast.visible = False
- ButtonEdit.visible = False
- ButtonDone.visible = False
- ButtonFind.visible = False
- ButtonNew.visible = False
- ButtonOK.visible = True
- ButtonCancel.visible = True
- If mode = EDIT_MODE Then
- ButtonDelete.visible = True
- End If
- End If
- If mode = VIEW_MODE Then
- ' If a record was locked, unlock it
- ' this may already have been done,
- ' but make the function call again to be safe...
- '
- rc = UnlockRec(CUSTOMER_TABLE)
- '
- ButtonFirst.visible = True
- ButtonNext.visible = True
- ButtonPrior.visible = True
- ButtonLast.visible = True
- ButtonEdit.visible = True
- ButtonDone.visible = True
- ButtonFind.visible = True
- ButtonNew.visible = True
- ButtonOK.visible = False
- ButtonCancel.visible = False
- ButtonDelete.visible = False
- End If
- If mode = ADD_MODE Then
- custnumber.enabled = False
- Else
- custnumber.enabled = True
- End If
- '
- ' Set global value as mode indicator
- '
- iMode = mode
- End Sub
-